using System.Collections.Generic;

namespace PascalsTriangleII
{
    public class Solution
    {
        public IList<int> GetRow(int rowIndex)
        {
            IList<int> pre = new List<int>() { 1 };
            IList<int> current = new List<int>();

            for (var i = 1; i <= rowIndex; i++)
            {
                for (var j = 0; j <= i; j++)
                {
                    if (j == 0 || j == i)
                    {
                        current.Add(1);
                    }
                    else
                    {
                        current.Add(pre[j - 1] + pre[j]);
                    }
                }
                pre = current;
                current = new List<int>();
            }
            return pre;
        }
    }
}